package com.gmd.model.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.gmd.model.Cita;
import com.gmd.model.dao.CitaDAO;

public class JPACitaDAO implements CitaDAO{
	private EntityManager em;
	public JPACitaDAO(EntityManager em) {
		this.em=em;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Cita> findAll() {
		Query query=em.createQuery("Select o From citas o");
		return query.getResultList();
	}

	@Override
	public Cita findById(int id) {
		return em.find(Cita.class, id);
	}

	@Override
	public Cita insert(Cita o) {
		em.persist(o);
		return o;
	}

	@Override
	public void update(Cita o) {
		em.merge(o);
		
	}

	@Override
	public void delete(Cita o) {
		em.remove(findById(o.getIdcita()));
		
	}

}
